package rohyunji;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.TextField;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ReadCompany extends JPanel
{
	String cp_no=null;
	CompanyVO cv=new CompanyVO();
	CompanyDAO cdao=new CompanyDAO();
	
	public ReadCompany(String cp_number,final CardLayout menu2AreaCard, final JPanel menuArea2,final CardLayout rightCard,final JPanel right_area) {
		// TODO Auto-generated constructor stub
		
		
		cp_no=cp_number;
		
		System.out.println(cp_no);
		
		setLayout(new BorderLayout(0, 0));
		
		setBackground(Color.red);
		
		JPanel panel = new JPanel();
		add(panel, BorderLayout.NORTH);
		
		JLabel label = new JLabel("기업정보관리");
		panel.add(label);
		

		
		JPanel panel_2 = new JPanel();
		add(panel_2, BorderLayout.EAST);
		
		JPanel panel_3 = new JPanel();
		add(panel_3, BorderLayout.WEST);
		
		JPanel panel_4 = new JPanel();
		add(panel_4, BorderLayout.CENTER);
		GridBagLayout gbl_panel_4 = new GridBagLayout();
		gbl_panel_4.columnWidths = new int[]{0, 0, 0, 0, 0};
		gbl_panel_4.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0};
		gbl_panel_4.columnWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		gbl_panel_4.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		panel_4.setLayout(gbl_panel_4);
		
		JLabel lblNewLabel_4 = new JLabel("사업자등록번호");
		GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
		gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_4.gridx = 1;
		gbc_lblNewLabel_4.gridy = 1;
		panel_4.add(lblNewLabel_4, gbc_lblNewLabel_4);
		
		JLabel cp_reg_no_lbl = new JLabel("");
		GridBagConstraints gbc_cp_reg_no_lbl = new GridBagConstraints();
		gbc_cp_reg_no_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_reg_no_lbl.gridx = 3;
		gbc_cp_reg_no_lbl.gridy = 1;
		panel_4.add(cp_reg_no_lbl, gbc_cp_reg_no_lbl);
		
		JLabel lblNewLabel_5 = new JLabel("기업명");
		GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
		gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_5.gridx = 1;
		gbc_lblNewLabel_5.gridy = 2;
		panel_4.add(lblNewLabel_5, gbc_lblNewLabel_5);
		
		JLabel cp_name_lbl = new JLabel("");
		GridBagConstraints gbc_cp_name_lbl = new GridBagConstraints();
		gbc_cp_name_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_name_lbl.gridx = 3;
		gbc_cp_name_lbl.gridy = 2;
		panel_4.add(cp_name_lbl, gbc_cp_name_lbl);
		
		JLabel lblNewLabel_6 = new JLabel("대표자명");
		GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
		gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_6.gridx = 1;
		gbc_lblNewLabel_6.gridy = 3;
		panel_4.add(lblNewLabel_6, gbc_lblNewLabel_6);
		
		JLabel cp_pre_lbl = new JLabel("");
		GridBagConstraints gbc_cp_pre_lbl = new GridBagConstraints();
		gbc_cp_pre_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_pre_lbl.gridx = 3;
		gbc_cp_pre_lbl.gridy = 3;
		panel_4.add(cp_pre_lbl, gbc_cp_pre_lbl);
		
		JLabel lblNewLabel_7 = new JLabel("주소");
		GridBagConstraints gbc_lblNewLabel_7 = new GridBagConstraints();
		gbc_lblNewLabel_7.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_7.gridx = 1;
		gbc_lblNewLabel_7.gridy = 4;
		panel_4.add(lblNewLabel_7, gbc_lblNewLabel_7);
		
		JLabel cp_addr_lbl = new JLabel("");
		GridBagConstraints gbc_cp_addr_lbl = new GridBagConstraints();
		gbc_cp_addr_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_addr_lbl.gridx = 3;
		gbc_cp_addr_lbl.gridy = 4;
		panel_4.add(cp_addr_lbl, gbc_cp_addr_lbl);
		
		JLabel lblNewLabel_8 = new JLabel("연락처");
		GridBagConstraints gbc_lblNewLabel_8 = new GridBagConstraints();
		gbc_lblNewLabel_8.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_8.gridx = 1;
		gbc_lblNewLabel_8.gridy = 5;
		panel_4.add(lblNewLabel_8, gbc_lblNewLabel_8);
		
		JLabel cp_phone_lbl = new JLabel("");
		GridBagConstraints gbc_cp_phone_lbl = new GridBagConstraints();
		gbc_cp_phone_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_phone_lbl.gridx = 3;
		gbc_cp_phone_lbl.gridy = 5;
		panel_4.add(cp_phone_lbl, gbc_cp_phone_lbl);
		
		JLabel lblNewLabel_9 = new JLabel("직종");
		GridBagConstraints gbc_lblNewLabel_9 = new GridBagConstraints();
		gbc_lblNewLabel_9.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_9.gridx = 1;
		gbc_lblNewLabel_9.gridy = 6;
		panel_4.add(lblNewLabel_9, gbc_lblNewLabel_9);
		
		JLabel cp_job_type_lbl = new JLabel("");
		GridBagConstraints gbc_cp_job_type_lbl = new GridBagConstraints();
		gbc_cp_job_type_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_job_type_lbl.gridx = 3;
		gbc_cp_job_type_lbl.gridy = 6;
		panel_4.add(cp_job_type_lbl, gbc_cp_job_type_lbl);
		
		JLabel lblNewLabel_10 = new JLabel("규모");
		GridBagConstraints gbc_lblNewLabel_10 = new GridBagConstraints();
		gbc_lblNewLabel_10.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_10.gridx = 1;
		gbc_lblNewLabel_10.gridy = 7;
		panel_4.add(lblNewLabel_10, gbc_lblNewLabel_10);
		
		JLabel cp_scale_lbl = new JLabel("");
		GridBagConstraints gbc_cp_scale_lbl = new GridBagConstraints();
		gbc_cp_scale_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_scale_lbl.gridx = 3;
		gbc_cp_scale_lbl.gridy = 7;
		panel_4.add(cp_scale_lbl, gbc_cp_scale_lbl);
		
		JLabel lblNewLabel_11 = new JLabel("사업개요");
		GridBagConstraints gbc_lblNewLabel_11 = new GridBagConstraints();
		gbc_lblNewLabel_11.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_11.gridx = 1;
		gbc_lblNewLabel_11.gridy = 8;
		panel_4.add(lblNewLabel_11, gbc_lblNewLabel_11);
		gbc_lblNewLabel_11.insets = new Insets(0, 0, 0, 5);
		gbc_lblNewLabel_11.gridx = 1;
		gbc_lblNewLabel_11.gridy = 10;
		
		JLabel cp_content_lbl = new JLabel("");
		GridBagConstraints gbc_cp_content_lbl = new GridBagConstraints();
		gbc_cp_content_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_content_lbl.gridx = 3;
		gbc_cp_content_lbl.gridy = 8;
		panel_4.add(cp_content_lbl, gbc_cp_content_lbl);
		
		JLabel lblNewLabel_12 = new JLabel("설립일");
		GridBagConstraints gbc_lblNewLabel_12 = new GridBagConstraints();
		gbc_lblNewLabel_12.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_12.gridx = 1;
		gbc_lblNewLabel_12.gridy = 9;
		panel_4.add(lblNewLabel_12, gbc_lblNewLabel_12);
		
		JLabel cp_incor_day_lbl = new JLabel("");
		GridBagConstraints gbc_cp_incor_day_lbl = new GridBagConstraints();
		gbc_cp_incor_day_lbl.insets = new Insets(0, 0, 5, 0);
		gbc_cp_incor_day_lbl.gridx = 3;
		gbc_cp_incor_day_lbl.gridy = 9;
		panel_4.add(cp_incor_day_lbl, gbc_cp_incor_day_lbl);
	
		
		
		cv.setCp_no(cp_no);

		for(CompanyVO v2:cdao.SelectCompany(cv))
		{
			cp_addr_lbl.setText(v2.getCp_addr());
			cp_content_lbl.setText(v2.getCp_content());
			cp_incor_day_lbl.setText(v2.getCp_incor_day());
			cp_job_type_lbl.setText(v2.getCp_job_type());
			cp_name_lbl.setText(v2.getCp_name());
			cp_phone_lbl.setText(v2.getCp_phone());
			cp_pre_lbl.setText(v2.getCp_pre());
			cp_reg_no_lbl.setText(v2.getCp_reg_no());
			cp_scale_lbl.setText(v2.getCp_scale());
		}
		
		JPanel panel_1 = new JPanel();
		add(panel_1, BorderLayout.SOUTH);
		
		JButton cp_update = new JButton("수정");
		panel_1.add(cp_update);
		JButton cp_delte = new JButton("삭제");
		
		panel_1.add(cp_delte);

		JButton cp_final = new JButton("확인");
		
		panel_1.add(cp_final);
		
		cp_update.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			
				JPanel cp_updatepage=new UpdateCompany(cp_no,menu2AreaCard,menuArea2,rightCard,right_area);
				right_area.add(cp_updatepage,"cp_updatepage");
				rightCard.show(right_area,"cp_updatepage");
//				
				
				
				
			}});
		
		
		cp_final.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			
				
				
				rightCard.show(right_area, "rightcard2");
				
				
			}});
		//수정버튼클릭시
	
		
		//삭제버튼
		cp_delte.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				cv.setCp_no(cp_no);
				CompanyDAO cdao=new CompanyDAO();
				if(cdao.deleteCompany(cv)){
					JOptionPane.showMessageDialog(null, "기업정보가 삭제되었습니다");
					
				}
				else
					JOptionPane.showMessageDialog(null, "기업정보가 삭제가 실패했습니다");
				
				
			}
		});
		
		setVisible(true);

    }

}
